package cn.yonyong.base.project.controller;

import cn.yonyong.base.project.config.AOP.annotation.Log;
import cn.yonyong.base.project.entity.Node;
import cn.yonyong.base.project.service.TreeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @Describtion ztree实践
 * @Author yonyong
 * @Date 2019/9/25 11:20
 * @Version 1.0.0
 **/
@Api(value = "/tree", tags = "tree接口")
@Controller
@RequestMapping("tree")
public class TreeController {

    @Autowired
    private TreeService treeService;

    @RequestMapping(value = "getDepartTree",method = RequestMethod.POST)
    @ResponseBody
    public List<Node> getDepartTree(){
        List<Node> nodeList = new ArrayList<Node>();
        nodeList.add(new Node("1","0","硬件规格","false","true"));
        nodeList.add(new Node("10","1","单板","false","true"));
        nodeList.add(new Node("11","1","子卡","false","true"));
        nodeList.add(new Node("12","1","设备","false","true"));
        nodeList.add(new Node("2","0","软件规格","false","true"));
        nodeList.add(new Node("20","2","java","false","true"));
        nodeList.add(new Node("21","2","jscript","false","true"));
        nodeList.add(new Node("22","2","php","false","true"));
        return nodeList;
    }

    @RequestMapping("/asyncGetNodes")
    @ResponseBody
    public List<Node> asyncGetNodes(String id, String pid, String name) throws Exception{
        List<Node> nodeList = new ArrayList<Node>();
        if(id.equals("10")){
            nodeList.add(new Node("100",id,"单板_00","false","false"));
            nodeList.add(new Node("101",id,"单板_01","false","false"));
        }
        Thread.sleep(3000);
        return nodeList;
    }

    @RequestMapping("/getTreeData")
    @ResponseBody
    @Log(value = "构建部门树",comment = "数据库中的tbldepartment表")
    public Object  getTreeData(String root_id, String departCode, String parentCode){

        return treeService.getAsyncAffixTreeData(root_id,departCode,parentCode);
    }
}
